<template>
  <el-tabs v-model="activeName">
    <el-tab-pane label="基础信息" name="first">

  <div>
    <div>
      <!-- 客档信息 -->
      <FormPanel
        v-loading="loading"
        ref="formPanel"
        :list="formList1"
        :cols="3"
        :formType="type"
        labelWidth="90"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"
      />
    </div>
    <!-- 意向车型 -->
    <BreakSpace label="意向车型" />
    <FilterTable
      v-loading="loading"
      ref="tableA"
      :columns="columns1"
      height="auto"
      :dataSource="intentDTOList"
      :isPagination="false"
      selectionType="single"
      :onSyncTableData="YXListChangeHandle"
      :onRowSelectChange="selectChangeHandle_intentCar"
      :defaultSelections="selectedList_intentCar"
      :onColumnsChange="columns1 => this.columns1 = columns1"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandleYX()">新增</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visibleYX"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <addYXcar
        :type="handleType"
        :hasData="YXCarTypeList"
        :rowData="formDataYX"
        @close="closeHandler"
        @YXHandle="YXHandle"
      />
    </BaseDialog>

    <!-- 联系人信息 -->
    <BreakSpace label="联系人信息" />
    <FilterTable
      v-loading="loading"
      ref="tableB"
      :columns="columns2"
      height="auto"
      :dataSource="customerContactinfoDTOList"
      :isPagination="false"
      selectionType="single"
      :onRowSelectChange="selectChangeHandle_customer"
      :defaultSelections="selectedList_customer"
      :onColumnsChange="columns2 => this.columns2 = columns2"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandleLX(props)">新增</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visibleLX"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <addContact
        :type="handleType"
        :rowData="formDataLX"
        :contantypeList="contantypeList"
        @close="closeHandler"
        @contactHandle="contactHandle"
      />
    </BaseDialog>
    <!-- 竞品车型 -->
    <BreakSpace label="竞品车型" />
    <FilterTable
      v-loading="loading"
      ref="tableD"
      :columns="columns3"
      height="auto"
      :dataSource="competitorDTOList"
      :isPagination="false"
      :isSelectColumn="false"
      selectionType="single"
      :onColumnsChange="columns3 => this.columns3 = columns3"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandleJP(props)">新增</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visibleJP"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <addJPcar
        :type="handleType"
        :rowData="formDataJP"
        @close="closeHandler"
        @JPHandle="JPHandle"
      />
    </BaseDialog>
    <!-- 保有车辆 -->
    <BreakSpace label="保有车辆" />
    <FilterTable
      v-loading="loading"
      ref="tableC"
      :columns="columns4"
      height="auto"
      :dataSource="keepingVehiclesDTOList"
      :isPagination="false"
      :isSelectColumn="false"
      selectionType="single"
      :onColumnsChange="columns4 => this.columns4 = columns4"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandleBY(props)">新增</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visibleBY"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <addBYcar
        :type="handleType"
        :rowData="formDataBY"
        @close="closeHandler"
        @BYHandle="BYHandle"
      />
    </BaseDialog>
    <!-- 转介绍客户弹框 -->
    <BaseDialog
      :visible.sync="visibleNAME"
      title="转介绍客户选择(精确查询)"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <searchName
        :type="handleType"
        :rowData="formDataNAME"
        @close="closeHandler"
        @NAMEHandle="NAMEHandle"
      />
    </BaseDialog>

    <!-- 更多信息 -->
    <FormPanel
      v-loading="loading"
      ref="formPanel3"
      :list="formList3"
      :cols="3"
      :formType="type"
      labelWidth="100"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <!-- <el-button @click="saveDialog('andFollow')">保存并跟进</el-button> -->
      <!-- <el-button @click="saveDialog('save')" :disabled="isDisabled" type="primary">保 存</el-button> -->
      <!-- 2019年12月23日，基盘点击续购不显示保存并跟进按钮 -->
      <AjaxButton
        v-if="type != 'addForbase'"
        :click="saveDialog.bind(this, 'andFollow')"
        type="primary"
        :disabled="isClickAgain"
      >保存并跟进</AjaxButton>
      <AjaxButton :click="saveDialog.bind(this, 'save')" type="primary">保存</AjaxButton>
    </div>
  </div>
   </el-tab-pane>
   <el-tab-pane  v-if="beijing" label="客户360视图">
         <clueLevelModel   :rowData="rowData"  />

 </el-tab-pane>
 
  </el-tabs>
</template>

<script>
import { getBrandList, getSeriesList, getModelList, getPackageList, getColorsList, getColorsListByOption, queryTccProductInfoById } from '@/api/potenCus/basedata/searchTestDriveCars';
import { getOptionListDictOEM } from '@/api/common/cars/masterDataCars';
import {
  queryEmployees,
  addNewLeads,
  updateNewLeads,
  getPotenCusById,
  queryCityList,
  getConsultantName,
  queryClueSourceList,
  getJPBrands,
  getJPSeries,
  getOrgType,
  getDealerArea,
  getCompanyOrgIsMerge,
  getIntentLevelsList, //意向级别
  getCarBuyingFactor, //购车因素
  getKnowWays, //了解途径
  getAllHeatUp,
  getActivePhoneInfo,
  getOrderInfo,
  updateDisposeStatusById
} from '@/api/potenCus/customer/potenCusManage';
import { getlistAllData } from '@/api/common/org/dealerCompany'; //城市接口
import { getCategories, getPartitionById } from '@/api/potenCus/basedata/cluesPrameter';
import { getUserInfo, getUserInfoByRolePosition } from '@/api/potenCus/customer/exhibition';
import addYXcar from './addDiaolg/addYXcar';
import addContact from './addDiaolg/addContact';
import addJPcar from './addDiaolg/addJPcar';
import addBYcar from './addDiaolg/addBYcar';
import searchDealers from './addDiaolg/searchDealers';
import searchName from './addDiaolg/searchName';
import AjaxButton from '@/components/AjaxButton';
import { getDataType, getAppId } from '@/assets/js/auth'; 
import { dictionary } from '@/utils/dictMixin';
import { authority } from '@/utils/authMixin';
import { isFormEmpty } from '@/utils/index';
import { getLoginUser } from '@/api/cms-api/projectOperating/program/departmentInquire';
import { IDNumber, phone, email, formatDates, formatDat, checkPassport, CheckSocialCreditCode } from '@/utils/validate';
import { notifyAction } from '@/utils';
import  clueLevelModel  from '../potenCusManageOEM/clueLevelModel';
export default {
  name: 'cluesModel',
  mixins: [dictionary, authority],
  components: {
    addYXcar,
    addContact,
    addJPcar,
    addBYcar,
    searchDealers,
    clueLevelModel,
    searchName
  },
  props: {
    type: {
      type: String,
      default: 'add'
    },
    rowData: {
      type: Object,
      default: () => ({})
    },
    RolePosition: {
      type: Array,
      default: () => []
    }
  },
  data() {
    this.saveData = null;
    return {
      dataType: getDataType('dataType'),
      roleType: localStorage.getItem('roleType'),
      listAllData: [],
      isMainIntent: '',
      activeName: 'first',
      isMain: '',
      isDeleted: '',
      isDisabled: false,
      dialogTitle: '',
      visibleYX: false,
      formDataYX: {},
      visibleLX: false,
      formDataLX: {},
      visibleJP: false,
      formDataJP: {},
      visibleBY: false,
      formDataBY: {},
      visibleNAME: false,
      formDataNAME: {},
      beijing:getAppId()=="beijing"?true:false, 
      intentDTOList: [], //意向车型
      customerContactinfoDTOList: [], //联系人
      competitorDTOList: [], //竞品车型
      keepingVehiclesDTOList: [], //保有车辆
      formList1: this.createFormList1(),
      formList3: this.createFormList3(),
      fetchParams1: {},
      columns1: this.createTableColumns1(),
      columns2: this.createTableColumns2(),
      columns3: this.createTableColumns3(),
      columns4: this.createTableColumns4(),
      handleType: '',
      formData: {},
      conf: { add: '新增', del: '删除', edit: '编辑' },
      // page: {
      //   pageNum: 1,
      //   currentPage: 1,
      //   pageSize: 100,
      //   limit: 100,
      //   isValid:10041001
      // },
      provinceId: '',
      cityId: '',
      contantypeList: this.createDictList('7034'),
      YXCarTypeList: [],
      introducCustomerId: null, // 转介绍客户id
      competitorArr: [],
      competitorArr2: [],
      consultsList: {},
      isClickAgain: false, //保存并跟进按钮禁用
      loading: false,
      showLIST: [],
      selectedList_intentCar: [], // 默认选中主车型
      selectedList_customer: [], // 默认选中主联系人
      selectedCarRows: [], //意向车型选中行
      selectedCustomerRows: [], //联系人选中行
      consultantId: ''
    };
  },
  created() {
    let { rowData } = this;
    this.init();
    this.getCityList();
    this.getClueTree();
    this.getIntentLevels(); // 获取意向
    this.getKnowWaysList(); // 获取了解途径
    this.getBuyCarList(); // 购车因素
    this.getAllHeatUp();
    // this.getEmployeeList()
    let roleType = this.dataType === 'clue' ? '10061012' : '10061012,10061015';
    this.getConsultant(1, roleType).then(result => {
      // console.log('顾问列表:' , result);
      // if (!result.some(item => item.value == rowData.currentConsultant)) {
      //   result.push({text: rowData.currentConsultantName, value: Number(rowData.currentConsultant)})
      // }
      this.consultsList = result;
      this.formList1.find(item => item.fieldName === 'consultant').itemList = result;
    });
  },
  mounted() {
      //af备注置灰 
      if(getAppId()=='arcfox'){ 
        this.formList1.find(x=>x.fieldName=='remark').disabled = true; 
      } 
  },
  methods: {
    async init() {
      if (this.type === 'show') {
        this.formList1.map(x => {
          x.rules = [];
        });
        this.formList3.map(x => {
          x.rules = [];
        });
      }
      console.log('rowData数据', this.type, this.rowData);
      if ((this.rowData.isEditPoten && this.rowData.isEditPoten === 10041001) || this.rowData.isComplete === 10041001) {
        this.isClickAgain = true;
        this.potentialCustomersId = this.rowData.customerBusinessId;
        await this.getPotenCusList();
      }
      //基盘addForbase
      if (this.type === 'edit' || this.type === 'show' || this.type == 'addForbase' || this.type === 'orderAdd') {
        // 更新接口需要的记录 ID
        this.potentialCustomersId = this.rowData.customerBusinessId;
        this.clueType = this.rowData.clueType;
        await this.getPotenCusList();
        await this.getCityList();
        // console.log('编辑的客户类型',this.formList1.find(x => x.fieldName === 'customerType').initialValue)
        // this.formList1.forEach(x => {
        //   x.initialValue = this.rowData[x.fieldName];
        // });
        this.isDisabled = false;
        this.formList1.find(item => item.fieldName === 'consultant').disabled = true;
      }

      await getUserInfo().then(res => {
        if (res.resultCode == 200) {
          this.userId = res.data.userInfo.userId;
          // console.log('self',this.userId)
          // let param = {
          //   menuId: 202040,
          //   positionCodes: [10061015, 10061012]
          // };
          // getConsultantName(param).then(res => {
          //   if(res.resultCode == 200){
          //     let employeeList = res.data.map(x => ({ value: x.userId, text: x.userName }));
          //     let LIST = []
          //     employeeList.forEach(item=>{
          //       if (LIST.length === 0) {
          //         LIST.push(item)
          //       } else {
          //         LIST.some(x => x.value === item.value) ? '' : LIST.push(item)
          //       }
          //     })
          //     //20191121合并所属顾问下拉值this.RolePosition
          //     this.formList1.find(item=>item.fieldName==='consultant').itemList = _.uniq(LIST.concat(this.RolePosition))
          //   }else{
          //     this.$message.error('获取人员列表失败!');
          //   }
          // })
        } else {
          // this.$message.error('获取当前登录用户信息失败!');
        }
      });
      // console.log('userId',this.userId)
      if (this.type === 'add') {
        // console.log("890",this.roleType)
        let roleType = this.roleType.split(',');
        if (roleType.includes('10061019') || roleType.includes('10061013')) {
          // console.log("8900")
          // this.formList1.find(item=>item.fieldName==='consultant').initialValue = '';
        } else {
          await this.getCityList();
          this.formList1.find(item => item.fieldName === 'consultant').initialValue = this.userId;
          this.formList1.find(item => item.fieldName === 'consultant').disabled = true;
        }
      }
      //展厅接待建档数据exhibitionAdd
      if (this.type == 'exhibitionAdd') {
        this.formList1.forEach(x => {
          x.initialValue = this.rowData[x.fieldName];
        });
        //新增手机号不能编辑
        this.formList1.find(item => item.fieldName === 'mobilePhone').disabled = true;
        this.formList1.find(item => item.fieldName === 'consultant').disabled = true;
        this.formList1.find(item => item.fieldName === 'consultant').initialValue = this.rowData.consultantCode;
      }
      this.isDisabled = false;
      // this.columns3.find(item => item.fieldName === 'competitorList').initialValue=
    },
    // 客档信息
    createFormList1() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '客户信息',
          style: {}
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          maxlength: 30,
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入客户名称', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '客户类型',
          fieldName: 'customerType',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1523'),
          disabled: this.type === 'addForbase' ? true : false,
          change: val => {
            console.log('val', val);
            if (val === 15231001) {
              this.formList1.find(item => item.fieldName === 'customerType').initialValue = 15231001;
              this.formList1.find(item => item.fieldName === 'contactName').hidden = true;
              this.formList1.find(item => item.fieldName === 'gender').label = '性别';
              this.formList1.find(item => item.fieldName === 'mobilePhone').label = '手机号码';
            }
            if (val === 15231003) {
              // this.contactName == this.formList1.find(item => item.fieldName ==='customerName').initialValue
              this.formList1.find(item => item.fieldName === 'customerType').initialValue = 15231003;
              this.formList1.find(item => item.fieldName === 'contactName').hidden = false;
              this.formList1.find(item => item.fieldName === 'gender').label = '联系人性别';
              this.formList1.find(item => item.fieldName === 'mobilePhone').label = '联系人手机';
            }
          },
          rules: [{ required: true, message: '请选择客户类型', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '联系人姓名',
          fieldName: 'contactName',
          placeholder: '请输入',
          hidden: true,
          rules: [{ required: true, message: '请输入联系人姓名', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '性别',
          fieldName: 'gender',
          placeholder: '请选择',
          hidden: false,
          itemList: this.createDictList('1002'),
          rules: [{ required: true, message: '请选择性别', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '手机号码',
          fieldName: 'mobilePhone',
          placeholder: '请输入',
          maxlength: 11,
          disabled: this.type === 'addForbase' ? true : false,
          rules: [
            { required: true, message: '请输入手机号码', trigger: 'blur' },
            { trigger: 'blur', validator: phone }
          ],
          onInput: tel => {
            var reg = /^1[3-9]\d{9}$/;
            console.log('手机', reg.test(tel));
            if (reg.test(tel) == true) {
              getActivePhoneInfo(tel).then(res => {
                console.log('查询号码信息', res);
                const { exist, errMsg, clueRecordId } = res.data;
                if (res.resultCode === 200) {
                  if (exist === 2) {
                    // 其他顾问线索
                    this.$message.info(errMsg);
                    return;
                  } else if (exist === 1) {
                    // 本人线索跳编辑
                    this.loading = true;
                    this.type == 'edit';
                    this.changeTitle();
                    this.potentialCustomersId = clueRecordId;
                    this.getPotenCusList();
                  } else if (exist === 3) {
                    // 战败线索跳新增
                    this.loading = true;
                    this.type == 'add';
                    this.potentialCustomersId = clueRecordId;
                    this.getPotenCusList();
                  } else if (exist === 4) {
                    this.loading = true;
                    this.type == 'add';
                    this.customerBusinessId = clueRecordId;
                    this.getOrderCusList();
                  } else {
                    // exist ===0  不存在 正常新增
                  }
                }
              });
            }
          }
        },
        {
          type: 'INPUT_TREE',
          label: '来源渠道',
          fieldName: 'clueSourceId',
          disabled: this.type === 'edit',
          placeholder: '请选择',
          width: 150,
          defaultExpandAll: true,
          initialValue: '',
          itemList: [],
          rules: [{ required: true, message: '请选择来源渠道', trigger: 'change' }],
          change: val => {
            console.log('我都不知道我选的是什么', val);
            this.formList1.find(item => item.fieldName === 'clueSourceId').initialValue = val;
            let switchList = this.deepShowClone(this.formList1.find(item => item.fieldName === 'clueSourceId').itemList);
            // console.log('switchList', switchList)
            switchList.forEach(x => {
              if (val == x.value) {
                console.log('就要你', x);
                if (x.businessType === 70721001) {
                  this.formList1.find(item => item.fieldName === 'introducCustomerName').hidden = false;
                } else {
                  this.formList1.find(item => item.fieldName === 'introducCustomerName').hidden = true;
                }
              }
            });
          }
        },
        {
          type: 'INPUT',
          label: '来源备注',
          fieldName: 'clueSourceRemark',
          maxlength: 32,
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '线索热度',
          fieldName: 'temperature',
          placeholder: '',
          initialValue: '',
          disabled: this.type === 'addForbase' ? false : true,
          itemList: []
        },
        {
          type: 'SELECT',
          label: '意向级别',
          fieldName: 'intentLevel',
          disabled: this.type === 'addForbase' ? false : this.type === 'edit' ? true : false,
          placeholder: '请选择',
          itemList: [],
          rules: [{ required: true, message: '请选择意向级别', trigger: 'change' }]
        },
        {
          type: 'DATE',
          label: '预购日期',
          fieldName: 'bookingDate',
          dateType: 'exactdate',
          // format: 'yyyy-MM-DD HH:mm',
          placeholder: '请选择'
        },
        // {
        //   type: 'DATE',
        //   label: '期望用车日期',
        //   fieldName: 'expectedCarDate',
        //   dateType: 'exactdate',
        //   // format: 'yyyy-MM-DD HH:mm',
        //   placeholder: '请选择',
        // },
        {
          type: 'SELECT',
          label: '线索类型',
          fieldName: 'clueEnterType',
          placeholder: '请选择',
          disabled: this.type === 'addForbase' ? false : true,
          initialValue: 70191001,
          itemList: this.createDictList('7019')
        },
        {
          type: 'SELECT',
          label: '购买类型',
          fieldName: 'buyType',
          placeholder: '请选择',
          itemList: this.createDictList('7015')
        },
        // {
        //   type: 'SELECT',
        //   label: '业务分类',
        //   fieldName: 'businessClassify',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('7056'),
        // },
        {
          type: 'SELECT',
          label: '付款方式',
          fieldName: 'paymentMethod',
          placeholder: '请选择',
          itemList: this.createDictList('1426')
        },
        {
          type: 'SELECT',
          label: '所属顾问',
          fieldName: 'consultant',
          placeholder: '请选择',
          disabled: false,
          itemList: [],
          rules: [{ required: true, message: '请选择所属顾问', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '转介绍客户',
          fieldName: 'introducCustomerName',
          placeholder: '点击搜索',
          initialValue: '',
          readonly: true,
          hidden: true,
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={this.openReferral}></el-button>;
          }
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          maxlength: 128,
          selfCols: 2,
          rows: 1,
          disabled: false,
          placeholder: '请输入'
        },
        {
          type: 'MULTIPLE_CHECKBOX',
          label: '商机分析',
          fieldName: 'businessAnaly',
          placeholder: '',
          selfCols: 4,
          disabled: this.type === 'add' || this.type === 'exhibitionAdd' || this.type === 'orderAdd' ? false : true,
          itemList: [
            { value: 70431001, text: '邀约进店' },
            { value: 70431002, text: '建立关系' },
            { value: 70431003, text: '需求分析' },
            { value: 70431004, text: '产品介绍' },
            { value: 70431005, text: '试乘试驾' },
            { value: 70431006, text: '异议处理' },
            { value: 70431007, text: '价格商谈' },
            { value: 70431008, text: '定金订单' }
          ]
        }
      ];
    },
    // 更多
    createFormList3() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '更多信息',
          style: {}
        },
        {
          type: 'INPUT_NUMBER',
          label: '购买台次',
          fieldName: 'buyNum',
          placeholder: '请输入'
        },
        {
          type: 'MULTIPLE_SELECT',
          label: '购车因素',
          fieldName: 'buyCarFactorList',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '购车用途',
          fieldName: 'buyCarUse',
          placeholder: '请选择',
          itemList: this.createDictList('1511')
        },
        {
          type: 'SELECT',
          label: '购车预算',
          fieldName: 'carBudget',
          placeholder: '请选择',
          itemList: this.createDictList('7057')
        },
        {
          type: 'INPUT',
          label: '置换信息',
          fieldName: 'displacementInfo',
          placeholder: '请输入'
        },
        {
          type: 'INPUT_TREE',
          label: '了解途径',
          fieldName: 'waysToRoad',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '证件类型',
          fieldName: 'ctCode',
          placeholder: '请选择',
          disabled: this.type === 'addForbase' ? true : false,
          itemList: this.createDictList('1508'),
          change: val => {
            console.log(val);
            // TODO
            if (val == 15081001) {
              //身份证
              this.formList3.find(item => item.fieldName === 'certificateNo').rules = [{ required: false, trigger: 'blur', validator: IDNumber }];
            }
            if (val == 15081002) {
              //护照
              // this.formList3.find(item => item.fieldName ==='certificateNo').rules=[{ required: false, trigger: 'blur', validator: /^[A-Za-z]{1,16}/ }]
              this.formList3.find(item => item.fieldName === 'certificateNo').rules = [
                {
                  required: false,
                  trigger: 'blur',
                  validator: (rule, value, callback) => {
                    if (value === undefined || value === '' || value === null) {
                      callback();
                    }
                    const g = /^[0-9a-zA-Z]{1,9}$/;
                    if (!g.test(value)) {
                      callback(new Error('请输入正确的护照号码'));
                    }
                    callback();
                  }
                }
              ];
            }
            if (val == 15081003) {
              //统一社会信用代码
              // this.formList3.find(item => item.fieldName ==='certificateNo').rules=[{ required: false, trigger: 'blur', validator: CheckSocialCreditCode }]
              this.formList3.find(item => item.fieldName === 'certificateNo').rules = [
                {
                  required: false,
                  trigger: 'blur',
                  validator: (rule, value, callback) => {
                    if (value === undefined || value === '' || value === null) {
                      callback();
                    }
                    const g = /^[0-9A-Z]{1,18}$/;
                    if (!g.test(value)) {
                      callback(new Error('请输入18位统一社会信用代码'));
                    }
                    callback();
                  }
                }
              ];
            }
            // if(val==70351004 || val==70351005 ||val==70351006){   //军官证 士兵证 警官证
            //   this.formList3.find(item => item.fieldName ==='certificateNo').rules=[{ required: false, trigger: 'blur', validator: (rule, value, callback) => {
            //       if (value === undefined || value === '' || value === null) {
            //         callback()
            //       }
            //       const g = /^[a-zA-Z0-9]{7,21}$/
            //       if (!g.test(value)) {
            //         callback(new Error('请输入7-21位证件号码!'))
            //       }
            //       callback()
            //     }
            //   }]
            // }
          }
        },
        {
          type: 'INPUT',
          label: '证件号码',
          fieldName: 'certificateNo',
          disabled: this.type === 'addForbase' ? true : false,
          placeholder: '请输入',
          rules: [],
          onInput: card => {
            console.log('card', card);
            console.log('证件号', /^\d{6}(18|19|20)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(card) == true);
            if (/^\d{6}(18|19|20)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(card) == true) {
              let bir = card.substring(6, 10) + '-' + card.substring(10, 12) + '-' + card.substring(12, 14);
              console.log('bir', bir);
              this.formList3.find(item => item.fieldName === 'birthday').initialValue = bir;
            }
          }
        },
        {
          type: 'DATE',
          label: '出生日期',
          fieldName: 'birthday',
          dateType: 'exactdate',
          placeholder: '请选择'
        },
        {
          type: 'SELECT',
          label: '省',
          fieldName: 'province',
          placeholder: '请选择',
          initialValue: '',
          itemList: [],
          change: val => {
            // console.log('val',val)
            if (val == 3662) {
              this.formList3.find(item => item.fieldName === 'city').itemList = [{ text: '台湾', value: 3662 }];
              this.formList3.find(item => item.fieldName === 'area').itemList = [{ text: '台湾', value: 3662 }];
            } else if (val == 3663) {
              this.formList3.find(item => item.fieldName === 'city').itemList = [{ text: '香港', value: 3663 }];
              this.formList3.find(item => item.fieldName === 'area').itemList = [{ text: '香港', value: 3663 }];
            } else if (val == 3664) {
              this.formList3.find(item => item.fieldName === 'city').itemList = [{ text: '澳门', value: 3664 }];
              this.formList3.find(item => item.fieldName === 'area').itemList = [{ text: '澳门', value: 3664 }];
            }
            let city = [];
            this.formList3.find(item => item.fieldName === 'city').initialValue = '';
            this.formList3.find(item => item.fieldName === 'city').itemList = [];
            this.formList3.find(item => item.fieldName === 'area').initialValue = '';
            this.formList3.find(item => item.fieldName === 'area').itemList = [];

            this.listAllData.forEach(x => {
              // 筛选省
              if (x.parentRegionId == val) {
                city.push({ text: x.regionName, value: x.regionId });
                this.formList3.find(item => item.fieldName === 'city').itemList = _.uniqBy(city, 'value');
              }
            });
          }
        },
        {
          type: 'SELECT',
          label: '市',
          fieldName: 'city',
          placeholder: '请选择',
          initialValue: '',
          itemList: [],
          change: val => {
            // console.log('val',val)
            let area = [];
            this.formList3.find(item => item.fieldName === 'area').initialValue = '';
            this.formList3.find(item => item.fieldName === 'area').itemList = [];
            this.listAllData.forEach(x => {
              // 筛选省
              if (x.parentRegionId == val) {
                // console.log('val111',val)
                area.push({ text: x.regionName, value: x.regionId });
                this.formList3.find(item => item.fieldName === 'area').itemList = _.uniqBy(area, 'value');
              }
            });
          }
        },
        {
          type: 'SELECT',
          label: '区',
          fieldName: 'area',
          placeholder: '请选择',
          initialValue: '',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '详细地址',
          selfCols: 2,
          fieldName: 'address',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '电子邮箱',
          fieldName: 'eMail',
          placeholder: '请输入',
          rules: [{ required: false, trigger: 'blur', validator: email }]
        },
        {
          type: 'INPUT',
          label: '微信',
          fieldName: 'wechart',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: 'QQ',
          fieldName: 'qq',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '固定电话',
          fieldName: 'phone',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '喜欢的联系方式',
          fieldName: 'likeContactWay',
          placeholder: '请选择',
          itemList: this.createDictList('7058')
        },
        {
          type: 'SELECT',
          label: '教育水平',
          fieldName: 'educationalLevel',
          placeholder: '请选择',
          itemList: this.createDictList('7027')
        },
        {
          type: 'SELECT',
          label: '婚姻状况',
          fieldName: 'maritalStatus',
          placeholder: '请选择',
          itemList: this.createDictList('7028')
        },
        {
          type: 'SELECT',
          label: '日常驾乘人数',
          fieldName: 'drivingNumber',
          placeholder: '请选择',
          itemList: this.createDictList('7059')
        },
        {
          type: 'SELECT',
          label: '是否有子女',
          fieldName: 'haveChildren',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          change: val => {
            console.log('你有孩子么', val);
            if (val === 10041001) {
              this.formList3.find(x => x.fieldName === 'haveChildren').initialValue = val;
              this.formList3.find(x => x.fieldName === 'childrenNumber').hidden = false;
            } else {
              this.formList3.find(x => x.fieldName === 'haveChildren').initialValue = val;
              this.formList3.find(x => x.fieldName === 'childrenNumber').initialValue = '';
              this.formList3.find(x => x.fieldName === 'childrenNumber').hidden = true;
            }
          }
        },
        {
          type: 'SELECT',
          label: '子女数量',
          fieldName: 'childrenNumber',
          placeholder: '请选择',
          hidden: true,
          itemList: this.createDictList('7060')
        },
        {
          type: 'INPUT_NUMBER',
          label: '家庭人数',
          fieldName: 'familyNum',
          placeholder: '请输入'
        },
        {
          type: 'INPUT_NUMBER',
          label: '家庭年收入(万)',
          fieldName: 'familyInCome',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '居住地类型',
          fieldName: 'liveType',
          placeholder: '请选择',
          itemList: this.createDictList('7061')
        },
        {
          type: 'SELECT',
          label: '工作地类型',
          fieldName: 'workPlaceType',
          placeholder: '请选择',
          itemList: this.createDictList('7062')
        },
        {
          type: 'SELECT',
          label: '企业性质',
          fieldName: 'enterpriseType',
          placeholder: '请选择',
          itemList: this.createDictList('7029')
        },
        {
          type: 'SELECT',
          label: '所属行业',
          fieldName: 'industry',
          placeholder: '请选择',
          itemList: this.createDictList('7030')
        },
        {
          type: 'SELECT',
          label: '职业',
          fieldName: 'postName',
          placeholder: '请选择',
          itemList: this.createDictList('7031')
        },
        {
          type: 'SELECT',
          label: '是否吸烟',
          fieldName: 'smokingOrNot',
          placeholder: '请选择',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '个人爱好',
          fieldName: 'avocation',
          placeholder: '请选择',
          itemList: this.createDictList('7032')
        },
        {
          type: 'SELECT',
          label: '钟爱饮料',
          fieldName: 'favoriteDrinks',
          placeholder: '请选择',
          itemList: this.createDictList('7033')
        }
      ];
    },
    // 意向车型
    createTableColumns1() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 80,
          fixed: 'right',
          render: (props, h, i) => {
            return (
              // <el-button type="text" size="medium" v-show={this.type == 'edit' ? true : false} onClick={() => this.editHandle1(props.row)}>
              //   <i class="el-icon-edit"></i>
              // </el-button>
              <div>
                <el-button type="text" size="medium" onClick={() => this.delHandle1(props.row)}>
                  <i class="el-icon-delete"></i>
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '意向品牌',
          dataIndex: 'intentBrandName',
          width: 200,
          filterType: 'input'
        },
        {
          title: '意向车系',
          dataIndex: 'intentSeriesName',
          filterType: 'input'
        },
        {
          title: '意向车型',
          dataIndex: 'intentModelName',
          width: 100,
          filterType: 'input'
        },
        {
          title: '意向配置',
          dataIndex: 'intentPackageName',
          width: 150,
          filterType: 'input'
        },
        {
          title: '意向选装',
          dataIndex: 'intentOptionName',
          width: 150,
          filterType: 'input'
        },
        // {
        //   title: '意向颜色',
        //   // dataIndex: 'intentColorId',
        //   dataIndex: 'intentColorName',
        //   width: 150,
        //   filterType: 'input'
        // },
        {
          title: '意向颜色（外饰）',
          dataIndex: 'intentColorName',
          width: 150,
          filterType: 'input'
        },
        {
          title: '意向颜色（内饰）',
          dataIndex: 'interiorName',
          width: 150,
          filterType: 'input'
        },
        {
          title: '意向颜色ID（外饰）',
          hidden: true,
          dataIndex: 'intentColor',
          width: 150,
          filterType: 'input'
        },
        {
          title: '意向颜色ID（内饰）',
          hidden: true,
          dataIndex: 'interiorId',
          width: 150,
          filterType: 'input'
        },

        {
          title: '购买备注',
          dataIndex: 'remark',
          filterType: 'input'
        }
      ];
    },
    // 联系人
    createTableColumns2() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 80,
          fixed: 'right',
          render: (props, h) => {
            return (
              // <el-button type="text" size="medium" v-show={this.type =='edit'? true:false} onClick={() => this.editHandle2(props.row)}>
              //   <i class="el-icon-edit"></i>
              // </el-button>
              <div>
                <el-button type="text" size="medium" onClick={() => this.delHandle2(props.row)}>
                  <i class="el-icon-delete"></i>
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '联系人姓名',
          dataIndex: 'contactName',
          filterType: 'input'
        },
        {
          title: '性别',
          dataIndex: 'gender',
          filterType: 'checkbox',
          filterItems: this.createDictList('1002'),
          render: props => {
            return <span>{this.createDictText(props.row.gender, '1002')}</span>;
          }
        },
        {
          title: '联系人手机',
          dataIndex: 'contactorPhone',
          filterType: 'input'
        },
        {
          title: '联系人类型',
          dataIndex: 'contactType',
          filterType: 'checkbox',
          filterItems: this.createDictList('7034'),
          render: props => {
            return <span>{this.createDictText(props.row.contactType, '7034')}</span>;
          }
        },
        {
          title: '关系',
          dataIndex: 'contactRelation',
          filterType: 'checkbox',
          filterItems: this.createDictList('1534'),
          render: props => {
            return <span>{this.createDictText(props.row.contactRelation, '1534')}</span>;
          }
        },
        {
          title: '备注',
          dataIndex: 'contactRemark',
          filterType: 'input'
        }
      ];
    },
    // 竞品
    createTableColumns3() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 60,
          fixed: 'right',
          render: (props, h) => {
            return (
              <div>
                <el-button type="text" size="medium" onClick={() => this.delHandle3(props.row)}>
                  <i class="el-icon-delete"></i>
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '竞争品牌',
          dataIndex: 'failBrand',
          filterType: 'input',
          render: props => {
            return <span>{props.row['failBrandName']}</span>;
          }
        },
        {
          title: '竞争车型',
          dataIndex: 'failSeries',
          filterType: 'input',
          render: props => {
            return <span>{props.row['failSeriesName']}</span>;
          }
        },
        {
          title: '竞品关注点',
          dataIndex: 'competitorList',
          filterType: 'checkbox',
          filterItems: [],
          render: props => {
            let DTOlist = this.columns3.find(item => item.dataIndex === 'competitorList').filterItems;
            // console.log('竞品关注点',props.row.competitorList)
            // console.log(23232,DTOlist)
            let templist = [];
            let basedataId = '';
            let basedataName = '';
            if (props.row.competitorList instanceof Array) {
              // console.log(basedataName,"Array")
              if (props.row.competitorList.length > 0) {
                // console.log(props.row.competitorList,">0")
                this.competitorArr2 = props.row.competitorList;
                props.row.competitorList.forEach((item, k) => {
                  DTOlist.forEach(x => {
                    if (item == x.value) {
                      basedataName += x.text + ',';
                    }
                  });
                });
              } else {
                console.log(props.row.competitorList, '<0');
                basedataName = props.row.competitorList;
              }
            } else {
              // console.log(basedataName,"basedataName")
              basedataName = props.row.competitorList;
            }
            // templist.push(basedataId)
            // console.log(basedataId,"basedataId")
            return <span>{basedataName}</span>;
          }
        },
        {
          title: '备注',
          dataIndex: 'competitorRemark',
          sorter: true,
          filterType: 'input'
        }
      ];
    },
    // 保有
    createTableColumns4() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 80,
          fixed: 'right',
          render: (props, h) => {
            return (
              // <el-button type="text" size="medium" v-show={this.type =='edit'? true:false} onClick={() => this.editHandle4(props.row)}>
              //   <i class="el-icon-edit"></i>
              // </el-button>
              <div>
                <el-button type="text" size="medium" onClick={() => this.delHandle4(props.row)}>
                  <i class="el-icon-delete"></i>
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '品牌',
          dataIndex: 'keepVehiclesBrand',
          filterType: 'input',
          filterItems: []
        },
        {
          title: '车系',
          dataIndex: 'keepVehiclesSeries',
          filterType: 'input',
          filterItems: []
        },
        {
          title: '车型',
          dataIndex: 'keepVehiclesModel',
          filterType: 'input',
          filterItems: []
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          filterType: 'input'
        },
        {
          title: '购买日期',
          dataIndex: 'buyDate',
          width: 160,
          initialValue: '',
          filterType: 'input',
          dateType: 'exactdate'
          // render: props => {
          //   return <span>{ formatDat(props.row.buyDate) }</span>;
          // }
        },
        {
          title: '购买车龄(天)',
          dataIndex: 'boughtCarsAge',
          filterType: 'input'
          // render: props => {
          //   return <span>{ props.row.boughtCarsAge/365 }</span>
          // }
        },
        {
          title: '行驶里程(km)',
          dataIndex: 'drivingMileage',
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'keepingRemark',
          filterType: 'input'
        }
      ];
    },
    // 是否显示转介绍
    deepShowClone(data) {
      if (data && data.length && Object.prototype.toString.call(data) == '[object Array]') {
        for (let i in data) {
          if (data[i].children && [].concat(data[i].children).length > 0) {
            this.deepShowClone(data[i].children);
          } else {
            this.showLIST.push({
              text: data[i].clueName,
              value: data[i].value,
              businessType: data[i].businessType
            });
          }
        }
      }
      return this.showLIST;
    },
    // 来源渠道限制
    deepListClone(data) {
      let tempList = [];
      // console.log('deepListClone',Object.prototype.toString.call(data),data)
      if (data && data.length && Object.prototype.toString.call(data) == '[object Array]') {
        for (let i in data) {
          if (data[i].children && [].concat(data[i].children).length > 0) {
            tempList[i] = {
              text: data[i].clueName,
              value: data[i].value,
              parentId: data[i].parentId,
              disabled: true,
              businessType: data[i].businessType,
              children: this.deepListClone([].concat(data[i].children))
            };
          } else {
            tempList[i] = {
              text: data[i].clueName,
              value: data[i].value,
              parentId: data[i].parentId,
              disabled: false,
              businessType: data[i].businessType
            };
          }
        }
      }
      return tempList;
    },
    // 来源渠道
    async getClueTree() {
      const res = await queryClueSourceList({ dataType: 70261002 });
      // console.log('来源渠道1', res)
      let treeList = this.deepListClone([].concat(res.data));
      // console.log('处理后来源',treeList)
      this.formList1.find(item => item.fieldName === 'clueSourceId').itemList = treeList;
      if (this.type != 'add') {
        this.formList1.find(item => item.fieldName === 'clueSourceId').initialValue = this.rowData.clueSourceId;
      }
    },
    formChangeHandle(val) {
      this.saveData = { ...this.saveData, ...val };
    },
    addHandleYX() {
      this.dialogTitle = '新增意向车型';
      this.handleType = 'add';
      this.visibleYX = true;
    },
    addHandleLX() {
      this.dialogTitle = '新增联系人';
      this.handleType = 'add';
      this.visibleLX = true;
    },
    addHandleJP() {
      this.dialogTitle = '新增竞品车型';
      this.handleType = 'add';
      this.visibleJP = true;
    },
    addHandleBY() {
      this.dialogTitle = '新增保有车辆';
      this.handleType = 'add';
      this.visibleBY = true;
    },
    // 意向车型编辑
    editHandle1(row) {
      // console.log('意向车编辑', row)
      this.dialogTitle = '编辑意向车型';
      this.handleType = 'edit';
      this.formDataYX = row;
      this.visibleYX = true;
    },
    // 意向车型删除
    delHandle1(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // TODO:删除数据
          this.intentDTOList = this.intentDTOList.filter(item => {
            return item.index !== row.index;
          });
          // 重写序号
          this.intentDTOList.forEach((item, index) => {
            item.index = index;
          });
          this.$message.success('删除成功');
        })
        .catch(() => {
          this.$message.info('已取消删除');
        });
      this.handleType = 'del';
    },
    // 联系人编辑
    editHandle2(row) {
      console.log('联系人编辑', row);
      this.dialogTitle = '编辑联系人';
      this.handleType = 'edit';
      this.formDataLX = row;
      this.visibleLX = true;
    },
    delHandle2(row) {
      // console.log('del2', this.customerContactinfoDTOList)
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // TODO:删除数据
          this.customerContactinfoDTOList = this.customerContactinfoDTOList.filter(item => {
            return item.index !== row.index;
          });
          // 重写序号
          this.customerContactinfoDTOList.forEach((item, index) => {
            item.index = index;
          });
          if (row.contactType === 70341001) {
            this.contantypeList = this.createDictList('7034');
          }
          this.$message.success('删除成功');
        })
        .catch(() => {
          this.$message.info('已取消删除');
        });
      this.handleType = 'del';
    },
    delHandle3(row) {
      // console.log('del3', this.competitorDTOList)
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // TODO:删除数据
          this.competitorDTOList = this.competitorDTOList.filter(item => {
            return item.index !== row.index;
          });
          // 重写序号
          this.competitorDTOList.forEach((item, index) => {
            item.index = index;
          });
          this.$message.success('删除成功');
        })
        .catch(() => {
          this.$message.info('已取消删除');
        });
      this.handleType = 'del';
    },
    // 保有车编辑
    editHandle4(row) {
      console.log('保有编辑', row);
      this.dialogTitle = '编辑保有车辆';
      this.handleType = 'edit';
      this.formDataBY = row;
      this.visibleBY = true;
    },
    delHandle4(row) {
      // console.log('del4', this.keepingVehiclesDTOList)
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // TODO:删除数据
          this.keepingVehiclesDTOList = this.keepingVehiclesDTOList.filter(item => {
            return item.index !== row.index;
          });
          // 重写序号
          this.keepingVehiclesDTOList.forEach((item, index) => {
            item.index = index;
          });
          this.$message.success('删除成功');
        })
        .catch(() => {
          this.$message.info('已取消删除');
        });
      this.handleType = 'del';
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}`;
      this.visible = true;
    },
    // 转介绍
    openReferral() {
      this.visibleNAME = true;
    },
    // 获取编辑明细
    async getPotenCusList() {
      await getPotenCusById(this.potentialCustomersId, this.clueType).then(res => {
        if (res.resultCode === 200) {
          this.loading = false;
          console.log('编辑明细', res);
          // console.log("编辑省",res.data.province,res.data.city )
          this.provinceId = res.data.province;
          this.cityId = res.data.city;
          this.formList1.forEach(x => {
            // x.fieldName === 'consultant' && res.data['consultant'] ? x.initialValue = Number(res.data['consultant']) : x.initialValue = res.data[x.fieldName];
            // x.fieldName === 'businessAnaly' && res.data['businessAnaly'] ? x.initialValue = res.data['businessAnaly'].split(',').map(x => parseInt(x)) : [];
            if (x.fieldName === 'consultant' && res.data['currentConsultant']) {
              // x.initialValue = Number(res.data.currentConsultant)
              x.initialValue = res.data['currentConsultantName'];
              this.consultantId = Number(res.data.currentConsultant);
              // TODO:currentConsultant、currentConsultantName
            } else if (x.fieldName === 'businessAnaly' && res.data['businessAnaly']) {
              x.initialValue = res.data['businessAnaly'].split(',').map(x => parseInt(x));
            } else if (x.fieldName === 'introducCustomerName') {
              x.initialValue = `${res.data['introducCustomerName'] || ''}${res.data['introducCustomerPhone'] || ''}`;
              this.introducCustomerId = res.data['introducCustomerId'];
            }
            // 2020/1/7 yy注释 编辑正常回显意向级别
            // else if (x.fieldName === 'intentLevel') {
            //   let numLevel = res.data.intentLevel;
            //   if (numLevel == 15191010 || numLevel == 15191001 || numLevel == 15191002 || numLevel == 15191003) {
            //     x.initialValue = numLevel;
            //   } else {
            //     x.initialValue = '';
            //   }
            // }
            //  else if(){}
            else {
              x.initialValue = res.data[x.fieldName];
            }
          });
          if (this.type == 'addForbase') {
            this.formList1.find(x => x.fieldName === 'remark').initialValue = '';
          }
          // console.log('当前顾问',res.data['currentConsultant'])
          this.formList1.find(x => x.fieldName === 'bookingDate').initialValue = formatDat(res.data.bookingDate);
          this.formList1.find(x => x.fieldName === 'clueSourceId').initialValue = res.data.clueSourceId;

          if (res.data.customerType === 15231001) {
            this.formList1.find(item => item.fieldName === 'contactName').hidden = true;
            this.formList1.find(item => item.fieldName === 'gender').label = '性别';
            this.formList1.find(item => item.fieldName === 'mobilePhone').label = '手机号码';
          }
          if (res.data.customerType === 15231003) {
            // this.contactName == this.formList1.find(item => item.fieldName ==='customerName').initialValue
            this.formList1.find(item => item.fieldName === 'contactName').hidden = false;
            this.formList1.find(item => item.fieldName === 'contactName').initialValue = res.data.contactName;
            this.formList1.find(item => item.fieldName === 'gender').label = '联系人性别';
            this.formList1.find(item => item.fieldName === 'mobilePhone').label = '联系人手机';
          }

          this.formList3.forEach(x => {
            x.initialValue = res.data[x.fieldName];
          });
          if (this.type == 'addForbase') {
            //点击续购 购车用途未选值时 传空数组报错
            // this.formList3.find(x => x.fieldName === 'buyCarUse').initialValue=[]
            this.formList3.find(x => x.fieldName === 'buyCarUse').initialValue = null;
          }
          // 是否有子女
          if (res.data.haveChildren === 10041001) {
            this.formList3.find(x => x.fieldName === 'haveChildren').initialValue = res.data.haveChildren;
            this.formList3.find(x => x.fieldName === 'childrenNumber').hidden = false;
            this.formList3.find(x => x.fieldName === 'childrenNumber').initialValue = res.data.childrenNumber;
          } else if (res.data.haveChildren === 10041002) {
            this.formList3.find(x => x.fieldName === 'haveChildren').initialValue = res.data.haveChildren;
            this.formList3.find(x => x.fieldName === 'childrenNumber').hidden = true;
          }

          this.formList3.find(x => x.fieldName === 'buyCarFactorList').initialValue = [];
          res.data.buyCarFactorList.map(x => {
            // console.log(x,"购车因素")
            this.formList3.find(x => x.fieldName === 'buyCarFactorList').initialValue.push(x.basedataId);
          });
          this.formList3.find(x => x.fieldName === 'birthday').initialValue = formatDat(res.data.birthday);
          // this.formList3.find(x => x.fieldName === 'buyCarFactorList').itemList = res.data.buyCarFactorList.map(x => ({ value: x.basedataId, text: x.basedataName }));

          // 意向
          if (this.type != 'addForbase') {
            console.log('编辑的意向车型', res.data.clueIntentDTOList);
            if (res.data.clueIntentDTOList.length) {
              let carList = [];
              this.intentDTOList = res.data.clueIntentDTOList;
              this.intentDTOList.forEach(item => {
                item['intentBrand'] = item.intentBrandId;
                item['intentSeries'] = item.intentSeriesId;
                item['intentModel'] = item.intentModelId;
                item['intentPackage'] = item.intentPackageId;
                item['intentOption'] = item.intentOptionId;
                item['intentColor'] = item.intentColorId;
                if (item.isMainIntent === 10041001) {
                  carList.push(item);
                  this.selectedList_intentCar = carList;
                }
              });
            }
          } else {
            //基盘任务跟进
            this.formList3.find(x => x.fieldName === 'phone').initialValue = '';
            // console.log(this.formList1.find(x => x.fieldName === 'intentLevel').itemList,"cxcx")
            this.formList1.find(x => x.fieldName === 'intentLevel').initialValue = 15191001;
          }

          // 联系人
          if (res.data.customerContactinfoDTO.length) {
            console.log('编辑的联系人', res.data.customerContactinfoDTO);
            this.customerContactinfoDTOList = res.data.customerContactinfoDTO;
            this.customerContactinfoDTOList.forEach(item => {
              let customerList = [];
              if (item.isMain === 10041001) {
                customerList.push(item);
                // 20191230添加
                this.selectedList_customer = customerList;
              }
            });
          }
          // 竞品
          if (res.data.competitors.length) {
            // console.log('竞品',res.data.competitors)
            this.competitorDTOList = res.data.competitors;

            let basedataName = '';
            this.competitorDTOList.forEach(item => {
              item['failBrandName'] = item.failBrand;
              item['failSeriesName'] = item.failSeries;
              if (item.competitorList) {
                this.competitorArr = [];
                item.competitorList.forEach(item2 => {
                  this.competitorArr.push(item2.basedataId);
                  item['competitorList'] = [...this.competitorArr];
                });
              }
            });
          }
          // 保有
          if (res.data.keepingVehiclesDTO.length) {
            this.keepingVehiclesDTOList = res.data.keepingVehiclesDTO;
            this.keepingVehiclesDTOList.forEach(x => {
              x.buyDate = formatDat(x.buyDate);
            });
          }
        }
      });
    },
    // 成交客户的明细接口
    async getOrderCusList() {
      await getOrderInfo(this.customerBusinessId).then(res => {
        if (res.resultCode === 200) {
          this.loading = false;
          console.log('成交客户的明细', res);
          // console.log("编辑省",res.data.province,res.data.city )
          this.provinceId = res.data.province;
          this.cityId = res.data.city;
          this.formList1.forEach(x => {
            if (x.fieldName === 'consultant' && res.data['currentConsultant']) {
              // x.initialValue = Number(res.data.currentConsultant)
              x.initialValue = res.data['currentConsultantName'];
              this.consultantId = Number(res.data.currentConsultant);
              // TODO:currentConsultant、currentConsultantName
            } else if (x.fieldName === 'businessAnaly' && res.data['businessAnaly']) {
              x.initialValue = res.data['businessAnaly'].split(',').map(x => parseInt(x));
            } else if (x.fieldName === 'introducCustomerName') {
              x.initialValue = `${res.data['introducCustomerName'] || ''}${res.data['introducCustomerPhone'] || ''}`;
              this.introducCustomerId = res.data['introducCustomerId'];
            } else if (x.fieldName === 'intentLevel') {
              x.initialValue = '';
            } else if (x.fieldName === 'clueSourceId') {
              x.initialValue = res.data['clueSourceId'];
              this.formList1.find(item => item.fieldName === 'clueSourceId').disabled = true;
            } else {
              x.initialValue = res.data[x.fieldName];
            }
          });
          if (this.type == 'addForbase') {
            this.formList1.find(x => x.fieldName === 'remark').initialValue = '';
          }
          // console.log('当前顾问',res.data['currentConsultant'])
          this.formList1.find(x => x.fieldName === 'bookingDate').initialValue = formatDat(res.data.bookingDate);
          this.formList1.find(x => x.fieldName === 'clueSourceId').initialValue = res.data.clueSourceId;

          if (res.data.customerType === 15231001) {
            this.formList1.find(item => item.fieldName === 'contactName').hidden = true;
            this.formList1.find(item => item.fieldName === 'gender').label = '性别';
            this.formList1.find(item => item.fieldName === 'mobilePhone').label = '手机号码';
          }
          if (res.data.customerType === 15231003) {
            // this.contactName == this.formList1.find(item => item.fieldName ==='customerName').initialValue
            this.formList1.find(item => item.fieldName === 'contactName').hidden = false;
            this.formList1.find(item => item.fieldName === 'contactName').initialValue = res.data.contactName;
            this.formList1.find(item => item.fieldName === 'gender').label = '联系人性别';
            this.formList1.find(item => item.fieldName === 'mobilePhone').label = '联系人手机';
          }

          this.formList3.forEach(x => {
            x.initialValue = res.data[x.fieldName];
          });
          if (this.type == 'addForbase') {
            //点击续购 购车用途未选值时 传空数组报错
            // this.formList3.find(x => x.fieldName === 'buyCarUse').initialValue=[]
            this.formList3.find(x => x.fieldName === 'buyCarUse').initialValue = null;
          }
          // 是否有子女
          if (res.data.haveChildren === 10041001) {
            this.formList3.find(x => x.fieldName === 'haveChildren').initialValue = res.data.haveChildren;
            this.formList3.find(x => x.fieldName === 'childrenNumber').hidden = false;
            this.formList3.find(x => x.fieldName === 'childrenNumber').initialValue = res.data.childrenNumber;
          } else if (res.data.haveChildren === 10041002) {
            this.formList3.find(x => x.fieldName === 'haveChildren').initialValue = res.data.haveChildren;
            this.formList3.find(x => x.fieldName === 'childrenNumber').hidden = true;
          }

          this.formList3.find(x => x.fieldName === 'buyCarFactorList').initialValue = [];
          res.data.buyCarFactorList.map(x => {
            // console.log(x,"购车因素")
            this.formList3.find(x => x.fieldName === 'buyCarFactorList').initialValue.push(x.basedataId);
          });
          this.formList3.find(x => x.fieldName === 'birthday').initialValue = formatDat(res.data.birthday);

          // 意向
          if (this.type != 'addForbase') {
            console.log('编辑的意向车型', res.data.clueIntentDTOList);
          } else {
            //基盘任务跟进
            this.formList3.find(x => x.fieldName === 'phone').initialValue = '';
            // console.log(this.formList1.find(x => x.fieldName === 'intentLevel').itemList,"cxcx")
            this.formList1.find(x => x.fieldName === 'intentLevel').initialValue = 15191001;
          }

          // 联系人
          if (res.data.customerContactinfoDTO.length) {
            console.log('编辑的联系人', res.data.customerContactinfoDTO);
            this.customerContactinfoDTOList = res.data.customerContactinfoDTO;
            this.customerContactinfoDTOList.forEach(item => {
              let customerList = [];
              if (item.isMain === 10041001) {
                customerList.push(item);
                // 20191230添加
                this.selectedList_customer = customerList;
              }
            });
          }
          // 竞品
          if (res.data.competitors.length) {
            // console.log('竞品',res.data.competitors)
            this.competitorDTOList = res.data.competitors;

            let basedataName = '';
            this.competitorDTOList.forEach(item => {
              item['failBrandName'] = item.failBrand;
              item['failSeriesName'] = item.failSeries;
              if (item.competitorList) {
                this.competitorArr = [];
                item.competitorList.forEach(item2 => {
                  this.competitorArr.push(item2.basedataId);
                  item['competitorList'] = [...this.competitorArr];
                });
              }
            });
          }
          // 保有
          if (res.data.keepingVehiclesDTO.length) {
            this.keepingVehiclesDTOList = res.data.keepingVehiclesDTO;
            this.keepingVehiclesDTOList.forEach(x => {
              x.buyDate = formatDat(x.buyDate);
            });
          }
        }
      });
    },
    async getCityList() {
      // console.log("this.formList3省市区",this.provinceId,this.cityId)
      await getlistAllData().then(res => {
        // console.log('城市', res)
        let province = [];
        let initCity = [];
        let initCounty = [];
        this.listAllData = res.data;
        this.listAllData.forEach(x => {
          // 筛选省
          if (x.parentRegionId == null) {
            province.push({ text: x.regionName, value: `${x.regionId}` });
          }
          // 市
          if (this.provinceId) {
            if (x.parentRegionId == this.provinceId) {
              initCity.push({ text: x.regionName, value: `${x.regionId}` });
            }
          }
          if (this.cityId) {
            if (x.parentRegionId == this.cityId) {
              initCounty.push({ text: x.regionName, value: `${x.regionId}` });
            }
          }
        });
        this.formList3.find(item => item.fieldName === 'province').itemList = province;
        this.formList3.find(item => item.fieldName === 'city').itemList = initCity;
        this.formList3.find(item => item.fieldName === 'area').itemList = initCounty;
      });
    },
    async getBuyCarList() {
      const res = await getCarBuyingFactor();
      // console.log('购车因素', res)
      if (res.resultCode === 200) {
        this.formList3.find(item => item.fieldName === 'buyCarFactorList').itemList = res.data.map(x => ({ value: x.basedataId, text: x.basedataName }));
        // TODO
        this.columns3.find(item => item.dataIndex === 'competitorList').filterItems = res.data.map(x => ({ value: x.basedataId, text: x.basedataName }));
      }
    },
    async getIntentLevels() {
      const res = await getIntentLevelsList();
      // console.log('意向', res)
      let temp = res.data;
      const levelList = this.createDictList('1519');
      // console.log('意向111', levelList)
      let aimValueList = [];
      temp.forEach(item => {
        item.basedataCode = Number(item.basedataCode);
        if (aimValueList.length == 0) {
          aimValueList.push(item.basedataCode);
        } else {
          aimValueList.includes(item.basedataCode) ? '' : aimValueList.push(item.basedataCode);
        }
      });
      // let aimList = levelList.filter(item =>  aimValueList.includes(item.value))
      let aimList = aimValueList.map(item => {
        return levelList.find(x => x.value == item);
      });
      if (this.type == 'add' || this.type == 'exhibitionAdd') {
        this.formList1.find(item => item.fieldName === 'intentLevel').itemList = aimList.map(x => ({ value: x.value, text: x.text }));
      } else {
        this.formList1.find(item => item.fieldName === 'intentLevel').itemList = levelList.map(x => ({ value: x.value, text: x.text }));
        if (this.type == 'addForbase') {
          this.formList1.find(item => item.fieldName === 'intentLevel').disabled = false;
        } else {
          this.formList1.find(item => item.fieldName === 'intentLevel').disabled = true;
        }
      }
      // console.log('surprise',aimList, aimValueList)
    },
    // 了解途径限制最后一级
    deepListClone1(data) {
      let tempList = [];
      // console.log('deepListClone1',Object.prototype.toString.call(data),data)
      if (data && data.length && Object.prototype.toString.call(data) == '[object Array]') {
        for (let i in data) {
          if (data[i].children && [].concat(data[i].children).length > 0) {
            tempList[i] = {
              text: data[i].wayName,
              value: data[i].value,
              parentId: data[i].wayLevel,
              disabled: true,
              children: this.deepListClone1([].concat(data[i].children))
            };
          } else {
            tempList[i] = {
              text: data[i].wayName,
              value: data[i].value,
              parentId: data[i].wayLevel,
              disabled: false
            };
          }
        }
      }
      return tempList;
    },
    async getKnowWaysList() {
      const res = await getKnowWays();
      // console.log('了解途径', res)
      let waysList = this.deepListClone1([].concat(res.data));
      // waysList.forEach(el => (el.text = el.wayName))
      // waysList.forEach(el => (el.value = el.id))
      // waysList.forEach(el => (el.wayLevel = el.wayLevel))
      this.formList3.find(item => item.fieldName === 'waysToRoad').itemList = waysList;
      // this.formList3.find(item => item.fieldName ==='waysToRoad').initialValue = this.rowData.waysToRoad
    },
    async getEmployeeList() {
      // 如果是从展厅接待过来则替换接待顾问下拉值
      if (this.type == 'exhibitionAdd') {
        // this.formList1.find(item => item.fieldName === 'consultant').itemList =this.RolePosition
      } else {
        // const res = await queryEmployees();
        // // console.log('顾问', res)
        // if (res.resultCode === 200) {
        //   this.formList1[14].itemList = res.data.map(x => ({ value: x.userId, text: x.employeeName }));
        // }
      }
    },
    // 保存
    async saveDialog(saveType) {
      let that = this;
      let { keepingVehiclesDTOList, introducCustomerId } = this;
      this.$refs.formPanel.SUBMIT_FORM();
      const [err, data3] = await this.$refs.formPanel3.GET_FORM_DATA();
      if (err) return;
      if (this.saveData !== null) {
        let user = await getLoginUser({});
        if ('beijing' == user.data.appId && this.intentDTOList.length == 0) { 
          this.$message.warning('请添加意向车型!'); 
          return; 
        } else if (this.intentDTOList.length > 1) { 
          if (this.selectedCarRows.length < 1) {
            this.$message.warning('请选择主意向车型!');
            return;
          }
        } else if (this.intentDTOList.length == 1) {
          console.log(this.intentDTOList, '请选择主意向车型');
          this.intentDTOList[0].isMainIntent = 10041001;
        }

        if (this.customerContactinfoDTOList.length > 1) {
          if (this.selectedCustomerRows.length < 1) {
            this.$message.warning('请选择主联系人!');
            return;
          }
        } else if (this.customerContactinfoDTOList.length == 1) {
          console.log(this.customerContactinfoDTOList, '请选择主联系人');
          this.customerContactinfoDTOList[0].isMain = 10041001;
        }
        // console.log("省",this.formList3[8].itemList)
        let saveObj = {
          ...data3,
          ...this.saveData,
          consultant: this.consultantId,
          introducCustomerId: introducCustomerId,
          bookingDate: this.formList1.find(x => x.fieldName === 'bookingDate').initialValue
            ? new Date(this.formList1.find(x => x.fieldName === 'bookingDate').initialValue.replace(new RegExp('-', 'gm'), '/')).getTime()
            : '',
          // expectedCarDate: this.formList1.find(x => x.fieldName === 'expectedCarDate').initialValue ? new Date(this.formList1.find(x => x.fieldName === 'expectedCarDate').initialValue.replace(new RegExp("-","gm"),"/")).getTime():'',
          birthday: this.formList3.find(x => x.fieldName === 'birthday').initialValue
            ? new Date(this.formList3.find(x => x.fieldName === 'birthday').initialValue.replace(new RegExp('-', 'gm'), '/')).getTime()
            : '',
          // contactName: this.formList1[1].initialValue,
          potentialCustomersId: this.rowData.customerBusinessId,
          intentDTOList: this.intentDTOList,
          customerContactinfoDTOList: this.customerContactinfoDTOList,
          competitorDTOList: this.competitorDTOList,
          keepingVehiclesDTOList: JSON.parse(JSON.stringify(keepingVehiclesDTOList)),
          isFollow: '',
          operateType: 6
        };
        if (saveObj.competitorDTOList) {
          saveObj.competitorDTOList.forEach((x, k) => {
            let arr = [];
            x.competitorList.map(L => {
              if (L.basedataId) {
                arr.push(L);
              } else {
                arr.push({ basedataId: L });
              }
            });
            saveObj.competitorDTOList[k].competitorList = [...arr];
          });
        }
        let basedataIdList = [];
        this.formList3
          .find(x => x.fieldName === 'buyCarFactorList')
          .initialValue.map(x => {
            if (x.basedataId) {
              basedataIdList.push(x.basedataId);
            } else {
              basedataIdList.push(x);
            }
          });
        // console.log(basedataIdList,"basedataIdList")
        saveObj.buyCarFactorList = basedataIdList;
        if (saveObj.keepingVehiclesDTOList.length) {
          saveObj.keepingVehiclesDTOList.forEach((item, index) => {
            saveObj.keepingVehiclesDTOList[index].buyDate = Date.parse(item.buyDate);
          });
        }
        console.log('saveObj意向车型', saveObj.intentDTOList);
        // todo
        // saveObj.intentDTOList[0]['isMainIntent'] = 10041001
        // saveObj.customerContactinfoDTOList.forEach((item, index)=>{
        //   if(index == 0){
        //     item['isMain'] = 10041001
        //   } else{
        //     item['isMain'] = 10041002
        //   }
        // })
        // 选择顾问附带orgId
        // console.log("consultant",this.formList1.find(item => item.fieldName === 'consultant'))
        // console.log("this.consultsList ",this.consultsList )
        this.consultsList.forEach(item => {
          if (saveObj.consultant == item.value) {
            saveObj['orgId'] = item.orgId;
          }
        });
        saveObj.businessAnaly = saveObj.businessAnaly.toString();
        // this.isDisabled = true;
        let res = {};
        console.log('saveObj', saveObj);
        console.log('saveObj购车因素', saveObj.buyCarFactorList);
        // if(saveType === 'save' || saveType === 'andFollow'){
        console.log('你猜是保存还是并跟进', saveType, this.type);
        if (saveType === 'save') {
          saveObj.isFollow = 10041002;
          if (this.type === 'exhibitionAdd') {
            let updateDisposeStatusData = {
              id: this.rowData.id,
              operation: '2'
            };
            updateDisposeStatusById(updateDisposeStatusData);
            // console.log(this.type,"this.type",this.rowData.consultant,this.formList1.find(item => item.fieldName === 'consultant'))
            saveObj.consultant = this.rowData.consultantCode;
            saveObj.passengerFlowId = this.rowData.id;
            saveObj['orgId'] = this.rowData.orgId;
            if (this.type === 'add' || this.type === 'exhibitionAdd') {
              res = await addNewLeads(saveObj);
              if (res.resultCode != 200) {
                notifyAction(res.errMsg, 'error');
                return;
              }
              this.isDisabled = false;
            }
            if (this.type === 'edit') {
              res = await updateNewLeads(saveObj);
              this.isDisabled = false;
            }
            if (res.resultCode === 200) {
              this.closeDialog('refresh');
              this.isDisabled = false;
              this.$message.success('保存成功');
            }
          } else {
            if (this.type === 'add' || this.type === 'addForbase') {
              res = await addNewLeads(saveObj);
              if (res.resultCode != 200) {
                notifyAction(res.errMsg, 'error');
                return;
              }
              this.isDisabled = false;
            }
            if (this.type === 'edit' || this.type === 'orderAdd') {
              res = await updateNewLeads(saveObj);
              this.isDisabled = false;
            }
            if (res.resultCode === 200) {
              this.closeDialog('refresh');
              this.isDisabled = false;
              this.$message.success('保存成功');
            }
          }
        }
        if (saveType === 'andFollow') {
          console.log('杨洋', this.type, saveType);
          saveObj.isFollow = 10041001;
          if (this.type === 'exhibitionAdd') {
            saveObj.consultant = this.rowData.consultantCode;
            saveObj.passengerFlowId = this.rowData.id;
            saveObj['orgId'] = this.rowData.orgId;
            res = await addNewLeads(saveObj);
            if (res.resultCode != 200) {
              notifyAction(res.errMsg, 'error');
              return;
            }
            this.isDisabled = false;
            /* if (this.type === 'add') {
                  res = await addNewLeads(saveObj);
                  this.isDisabled = false;
                }
                if (this.type === 'edit') {
                  res = await updateNewLeads(saveObj);
                  this.isDisabled = false;
                } */
            console.log(res.resultCode, 'res.resultCode');
            if (res.resultCode == 200) {
              console.log('展厅建档保存并跟进数据', res);
              this.$message.success('保存成功并跟进');
              this.closeDialog1(res);
            }
          } else {
            if (this.type === 'add' || this.type === 'addForbase') {
              res = await addNewLeads(saveObj);
              if (res.resultCode != 200) {
                notifyAction(res.errMsg, 'error');
                return;
              }
              this.isDisabled = false;
            }
            if (this.type === 'edit') {
              res = await updateNewLeads(saveObj);
              this.isDisabled = false;
            }
            if (res.resultCode == 200) {
              console.log('保存并跟进数据', res);
              this.$message.success('保存成功并跟进');
              this.closeDialog1(res);
            }
          }
        }
        // }
        else {
          // this.$message.warning('请填写必填项!');
        }
      }
    },
    closeDialog(param) {
      this.$emit('close', false, param);
    },
    closeDialog1(param) {
      console.log('成功了没', param);
      this.$emit('fatherClose', param);
    },
    changeTitle(param) {
      console.log('你是什么垃圾', param);
      this.$emit('changeNAME', param);
    },
    // 转介绍
    NAMEHandle(data) {
      console.log('转介绍', data);
      if (data) {
        let aimString = `${data.customerName}${data.mobilePhone}`;
        // 需要提交的转介绍客户id
        this.introducCustomerId = data.potentialCustomersId;
        this.formList1.find(item => item.fieldName == 'introducCustomerName').initialValue = aimString;
      }
    },
    // 意向车型数据变化
    YXListChangeHandle(data) {
      // console.log('意向车型数据变化', data)
      if (data.length > 0) {
        this.YXCarTypeList = data.map(item => {
          return [item.intentBrandId, item.intentSeriesId, item.intentModelId, item.intentPackageId, item.intentColorId].toString();
        });
      } else {
        this.YXCarTypeList = [];
      }
    },
    // 选择主意向车型
    selectChangeHandle_intentCar(rows) {
      console.log(this.intentDTOList, '主车型是你', rows);
      if (!rows.length) return;
      this.selectedCarRows = rows[0];
      this.intentDTOList.forEach(x => {
        if (x.index == rows[0].index) {
          x.isMainIntent = 10041001;
        } else {
          x.isMainIntent = 10041002;
        }
      });
    },
    // 意向车型附带数据
    async YXHandle(data) {
      // console.log("YXcolumns1",this.columns1)
      // console.log("this.intentDTOList", this.intentDTOList)
      console.log('cc', data);
      data.intentBrand = data.intentBrandId;
      data.intentSeries = data.intentSeriesId;
      data.intentModel = data.intentModelId;
      data.intentPackage = data.intentPackageId;
      data.intentColor = data.intentColorId;
      data.intentOption = data.intentOptionId;
      this.columns1[2].initialValue = data.intentBrand;
      // console.log("意向车型",this.intentDTOList)

      await getBrandList().then(res => {
        //  console.log(res,"品牌",this.columns1)
        res.data.forEach(x => {
          if (data.intentBrand == x.brandId) {
            data.intentBrandName = x.brandName;
          }
        });
      });
      await getSeriesList(data.intentBrand).then(res => {
        //  console.log(res,"车系")
        res.data.forEach(x => {
          if (data.intentSeriesId == x.seriesId) {
            data.intentSeriesName = x.seriesName;
          }
        });
      });
      await getModelList(data.intentBrand, data.intentSeriesId).then(res => {
        //  console.log(res,"车型")
        res.data.forEach(x => {
          if (data.intentModelId == x.modelId) {
            data.intentModelName = x.modelName;
          }
        });
      });
      if (data.intentModelId) {
        await getPackageList(data.intentModelId).then(res => {
          // console.log(res,"配置")
          res.data.forEach(x => {
            if (data.intentPackageId == x.packageId) {
              data.intentPackageName = x.configName;
            }
          });
        });
      } else {
      }
      if (data.intentPackageId) {
        await getOptionListDictOEM(data.intentPackageId).then(res => {
          // console.log(res,"选装")
          res.data.forEach(x => {
            if (data.intentOptionId == x.optionId) {
              data.intentOptionName = x.optionName;
            }
          });
        });
      } else {
      }
      //  console.log(data.intentPackageId,"intentPackageId")

      if (data.productId) {
        await queryTccProductInfoById(data.productId).then(res => {
          //  console.log(res,"颜色")
          data.intentColorName = res.data.colorName;
          data.interiorName = res.data.trimColorName;
          data.intentColor = res.data.colorId;
          data.interiorId = res.data.trimColor;
          // res.data.forEach(x => {
          //   if (data.intentColorId == x.colorId) {
          //     data.intentColorName = x.colorName;
          //   }
          // });
        });
      } else {
      }
      if (this.handleType === 'edit') {
        const arr = [];
        const type = typeof this.selectedCarRows;
        let selectIndex;
        this.intentDTOList.map((item, i) => {
          if (data.sort == i) {
            data.index = i;
            arr[i] = data;
          } else {
            arr.push(item);
          }
          if (type === 'array' && this.selectedList_intentCar[0].clueIntentId === item.clueIntentId) {
            selectIndex = i;
          } else if (type === 'object' && this.selectedCarRows.clueIntentId === item.clueIntentId) {
            selectIndex = i;
          }
        });
        arr.dataMark = false;
        this.intentDTOList = arr;
        selectIndex && (this.selectedList_intentCar = this.intentDTOList.slice(selectIndex, 1));
      } else {
        this.insertDateInTableA({ index: this.intentDTOList.length, ...data });
        let { intentBrandId, intentSeriesId, intentModelId, intentPackageId, intentOptionId, intentColorId } = data;
        this.YXCarTypeList.push([intentBrandId, intentSeriesId, intentModelId, intentPackageId, intentOptionId, intentColorId].toString());
      }
    },
    // 选择主联系人
    selectChangeHandle_customer(rows) {
      // console.log(this.customerContactinfoDTOList,'主联系人是你', rows)
      if (!rows.length) return;
      this.selectedCustomerRows = rows[0];
      this.customerContactinfoDTOList.forEach(x => {
        if (x.index == rows[0].index) {
          x.isMain = 10041001;
        } else {
          x.isMain = 10041002;
        }
      });
    },
    // 联系人附带数据
    contactHandle(data) {
      console.log('联系人附带数据1', data);
      this.columns2[2].initialValue = data.intentBrand;
      // console.log("联系人",this.customerContactinfoDTOList)
      if (data.contactType === 70341001) {
        this.contantypeList = this.contantypeList.filter(item => item.value != data.contactType);
      }
      this.insertDateInTableB({
        index: this.customerContactinfoDTOList.length,
        contactName: data.contactName,
        gender: data.gender,
        contactorPhone: data.contactorPhone,
        contactType: data.contactType,
        contactRelation: data.contactRelation,
        contactRemark: data.contactRemark,
        // isMain: '',
        isDeleted: 0
      });
      // if(this.customerContactinfoDTOList.length==0){
      //   this.insertDateInTableB(
      //     { index:this.customerContactinfoDTOList.length,
      //       contactName: data.contactName,
      //       gender: data.gender,
      //       contactorPhone: data.contactorPhone,
      //       contactType: data.contactType,
      //       contactRelation: data.contactRelation,
      //       contactRemark: data.contactRemark,
      //       // isMain: '',
      //       isDeleted: 0,
      //     }
      //   )
      // }else{
      //   this.customerContactinfoDTOList.push(
      //   { index:this.customerContactinfoDTOList.length,
      //     contactName: data.contactName,
      //     gender: data.gender,
      //     contactorPhone: data.contactorPhone,
      //     contactType: data.contactType,
      //     contactRelation: data.contactRelation,
      //     contactRemark: data.contactRemark,
      //     // isMain: '',
      //     isDeleted: 0,
      //   })
      // }
    },
    async getAllHeatUp() {
      const res = await getAllHeatUp({ isValid: 10041001 });
      // console.log('客档热度定义', res)
      if (res.resultCode === 200) {
        this.formList1.find(item => item.fieldName === 'temperature').itemList = res.data.map(x => ({ value: x.id, text: x.clueHeatName }));
      }
    },
    // 竞品
    async JPHandle(data) {
      console.log('竞品附带', data);
      this.columns3[2].initialValue = data.failBrand;
      // console.log("竞品",this.competitorsList)
      // if( data.competitorList.length>0 ){
      await getJPBrands().then(res => {
        console.log(res, '竞品品牌');
        res.data.forEach(x => {
          if (data.failBrand == x.failModelId) {
            data.failBrand = x.failModelId;
            data['failBrandName'] = x.failBrand;
          }
        });
      });
      if (data.failBrand) {
        await getJPSeries(data.failBrand).then(res => {
          console.log(res, '竞品车系');
          res.data.forEach(x => {
            if (data.failSeries == x.failModelId) {
              data.failSeries = x.failModelId;
              data['failSeriesName'] = x.failSeries;
              data['failModelId'] = x.failModelId;
            }
          });
        });
      }
      this.insertDateInTableD({ index: this.competitorDTOList.length, ...data });
      // } else {

      // }
    },
    // 保有
    BYHandle(data) {
      console.log('保有附带', data);
      this.columns4[2].initialValue = data.keepVehiclesBrand;
      console.log('保有', this.keepingVehiclesDTOList);
      this.insertDateInTableC({ index: this.intentDTOList.length, ...data });
    },
    closeHandler(val, type) {
      this.visibleYX = val;
      this.visibleLX = val;
      this.visibleJP = val;
      this.visibleBY = val;
      this.visibleNAME = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    insertDateInTableA(obj) {
      this.$refs.tableA.EXECUTE_INSERT(obj);
      // 新增默认选中第一条数据 CYX-19356
      if (!this.selectedList_intentCar.length) {
        this.selectedList_intentCar = this.intentDTOList.slice(0, 1);
      }
    },
    insertDateInTableAAA(obj) {
      this.$refs.tableA.EXECUTE_DELETE(obj);
    },
    insertDateInTableB(obj) {
      this.$refs.tableB.EXECUTE_INSERT(obj);
    },
    insertDateInTableD(obj) {
      this.$refs.tableD.EXECUTE_INSERT(obj);
    },
    insertDateInTableC(obj) {
      this.$refs.tableC.EXECUTE_INSERT(obj);
    }
  }
};
</script>

<style lang="less" scoped>
</style>

